package org.example.seckill.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.example.seckill.service.OrderService;
import org.example.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(
        topic = "tp_seckill_order_01",
        consumerGroup = "seckill_order_consumer_grp_02",
        selectorExpression = "expire_order",
        consumeMode = ConsumeMode.CONCURRENTLY
)
public class SeckillExpireOrderListener implements RocketMQListener<String> {

    @Autowired
    private OrderService orderService;

    @Autowired
    private SeckillService seckillService;

    @Override
    public void onMessage(String message) {
        log.info(message);
        orderService.expireOrder(Integer.valueOf(message));
    }
}
